package com.xilihui.xlh.business.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xilihui.xlh.R;
import com.xilihui.xlh.business.entities.WithdrawDetailEntity;
import com.xilihui.xlh.business.requests.MineRequest;
import com.xilihui.xlh.core.app.BaseCompatActivity;
import com.xilihui.xlh.core.http.DoTransform;
import com.xilihui.xlh.core.http.HttpSubscriber;
import com.xilihui.xlh.core.util.ToastUtil;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/7/9.
 */

public class ShowDetailActivity extends BaseCompatActivity{
    
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_num)
    TextView tv_num;
    @BindView(R.id.tv_status)
    TextView tv_status;
    @BindView(R.id.tv_tx_jiner)
    TextView tv_txJiner;
    @BindView(R.id.tv_sxf)
    TextView tv_sxf;
    @BindView(R.id.tv_sqTime)
    TextView tv_sqTime;
    @BindView(R.id.tv_jjTime)
    TextView tv_jjTime;
    @BindView(R.id.tv_jjHint)
    TextView tv_jjHint;
    @BindView(R.id.tv_tx_type)
    TextView tv_txType;
    @BindView(R.id.tv_tx_danhao)
    TextView tv_danhao;
    
    @BindView(R.id.ll_shenqijujie)
    LinearLayout ll_shengqijujie;
    @BindView(R.id.ll_jujieyuanyin)
    LinearLayout ll_jujieyuanyin;
    
    String id = "";
    
    @Override
    public int getLayout() {
        return R.layout.activity_show_detail;
    }

    @Override
    public String initTitle() {
        return "提现详情";
    }

    @Override
    public void initUI(@Nullable Bundle savedInstanceState) {
        id = getIntent().getStringExtra("id");
    }

    @Override
    public void initData() {
        getData();
    }
    
    public void getData(){
        MineRequest.detail(ShowDetailActivity.this,id)
                .compose(DoTransform.<WithdrawDetailEntity>applyScheduler(this,true))
                .compose(this.<WithdrawDetailEntity>bindToLifecycle())
                .subscribe(new HttpSubscriber<WithdrawDetailEntity>(this) {
                    @Override
                    protected void onSuccess(WithdrawDetailEntity entity) {
                        tv_title.setText(entity.getData().getRemark());
                        tv_num.setText(entity.getData().getMoney());
                        handleStatus(entity.getData().getStatus());
                        tv_txJiner.setText(entity.getData().getMoney());
                        tv_sxf.setText(entity.getData().getTaxfee());
                        tv_sqTime.setText(entity.getData().getCreate_time());
                        tv_jjTime.setText(entity.getData().getRefuse_time());
                        tv_jjHint.setText(entity.getData().getDesc());
                        tv_txType.setText(entity.getData().getType());
                        tv_danhao.setText(entity.getData().getOrder_num());
                    }

                    @Override
                    protected void onFail(String msg) {
                        ToastUtil.toastShortNegative(msg);
                    }
                });
    }
    
    public void handleStatus(String status){
        int type = Integer.valueOf(status);
        
        switch (type){
            case -1:
                tv_status.setText("审核拒绝");
                tv_status.setTextColor(getResources().getColor(R.color.tv_fb4e44));
                break;
            case 0:
                tv_status.setText("申请中");
                tv_status.setTextColor(getResources().getColor(R.color.tv_333333));
                ll_shengqijujie.setVisibility(View.GONE);
                ll_jujieyuanyin.setVisibility(View.GONE);
                break;
            case 1:
                tv_status.setText("审核通过");
                tv_status.setTextColor(getResources().getColor(R.color.tv_59c04e));
                ll_shengqijujie.setVisibility(View.GONE);
                ll_jujieyuanyin.setVisibility(View.GONE);
                break;
            case 2:
                tv_status.setText("已发放");
                tv_status.setTextColor(getResources().getColor(R.color.tv_59c04e));
                ll_shengqijujie.setVisibility(View.GONE);
                ll_jujieyuanyin.setVisibility(View.GONE);
                break;
        }
        
    }

}
